package com.magina.antiPro.controller;


import com.magina.antiPro.domain.bo.AuthRoleResource;
import com.magina.antiPro.exception.BusinessException;
import com.magina.antiPro.response.Response;
import com.magina.antiPro.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.ExecutionException;

@Api(value = "/testAsyncTaskWithAffair", description = "测试异步异常接口回滚事务")
@RequestMapping("/testAsyncTaskWithAffair")
@RestController
@Slf4j
public class AsyncTaskTestWithAffairController {

    @Autowired
    private RoleService roleService;

    @ApiOperation(value = "Aysnc异常是否能回滚", notes = "Aysnc注入的异常是否在Service能否回滚main线程的事务")
    @PostMapping("/doTaskExceptionMethod_One")
    public Response doTaskExceptionMethod_One(@RequestBody AuthRoleResource authRoleResource ) throws InterruptedException, ExecutionException, BusinessException {
        log.info("========Aysnc异常是否能回滚========");
        long currentTimeMillis = System.currentTimeMillis();
        roleService.testAuthorityRoleResourceWithAsyncExcep(  authRoleResource );
        long currentTimeMillis1 = System.currentTimeMillis();
        return Response.succeed("Aysnc异常是否能回滚_任务总耗时:" + (currentTimeMillis1 - currentTimeMillis) + "ms");
    }

   }

